package com.ruoyi.resource.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.ruoyi.resource.domain.ResourceEnum;
import com.ruoyi.resource.domain.ResourceInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.resource.mapper.ResourceInfoMapper;
import com.ruoyi.resource.domain.ResourceInfo;
import com.ruoyi.resource.service.IResourceInfoService;

/**
 * 资源信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-05-14
 */
@Service
public class ResourceInfoServiceImpl implements IResourceInfoService 
{
    @Autowired
    private ResourceInfoMapper resourceInfoMapper;

    /**
     * 查询资源信息
     * 
     * @param id 资源信息主键
     * @return 资源信息
     */
    @Override
    public ResourceInfo selectResourceInfoById(Long id)
    {
        return resourceInfoMapper.selectResourceInfoById(id);
    }

    /**
     * 查询资源信息列表
     * 
     * @param resourceInfo 资源信息
     * @return 资源信息
     */
    @Override
    public List<ResourceInfoVO> selectResourceInfoList(ResourceInfo resourceInfo)
    {
        List<ResourceInfo> resourceInfos = resourceInfoMapper.selectResourceInfoList(resourceInfo);
        List<ResourceInfoVO> resourceInfoVOS = new ArrayList<>();
        for(ResourceInfo resource:resourceInfos) {
            ResourceInfoVO resourceInfoVO = new ResourceInfoVO();
            String type = Objects.requireNonNull(
                    ResourceEnum.valueOf(resource.getResourceType().intValue())).getName();
            resourceInfoVO.setResourceType(type);
            resourceInfoVO.setHasResource(resource.getHasResource()==1?"是":"否");
            resourceInfoVO.setScreenNumber("第"+ Math.toIntExact(resource.getScreenNumber()) +"屏");
            resourceInfoVO.setId(resource.getId());
            resourceInfoVOS.add(resourceInfoVO);
        }
        return resourceInfoVOS;
    }
    @Override
    public List<ResourceInfo> selectResourceInfoLists(ResourceInfo resourceInfo)
    {
        return  resourceInfoMapper.selectResourceInfoList(resourceInfo);

    }

    /**
     * 新增资源信息
     * 
     * @param resourceInfo 资源信息
     * @return 结果
     */
    @Override
    public int insertResourceInfo(ResourceInfo resourceInfo)
    {
        return resourceInfoMapper.insertResourceInfo(resourceInfo);
    }

    /**
     * 修改资源信息
     * 
     * @param resourceInfo 资源信息
     * @return 结果
     */
    @Override
    public int updateResourceInfo(ResourceInfo resourceInfo)
    {
        return resourceInfoMapper.updateResourceInfo(resourceInfo);
    }

    /**
     * 批量删除资源信息
     * 
     * @param ids 需要删除的资源信息主键
     * @return 结果
     */
    @Override
    public int deleteResourceInfoByIds(Long[] ids)
    {
        return resourceInfoMapper.deleteResourceInfoByIds(ids);
    }

    /**
     * 删除资源信息信息
     * 
     * @param id 资源信息主键
     * @return 结果
     */
    @Override
    public int deleteResourceInfoById(Long id)
    {
        return resourceInfoMapper.deleteResourceInfoById(id);
    }

}
